const callbackMap = new Map()

interface Emits{
    // eslint-disable-next-line no-unused-vars
    (eventName: string, ...items: unknown[]): void;
}

// eslint-disable-next-line func-names
const $emits:Emits = function (eventName:string) {
    const cbList = callbackMap.get(eventName) || []
    // eslint-disable-next-line prefer-rest-params
    const args = [...arguments]
    args.shift()
    if (cbList) {
        for (let i = 0; i < cbList.length; i++) {
            cbList[i](...args)
        }
    }
}
const $on = (eventName:string, callback:Function) => {
    const cbList = callbackMap.get(eventName) || []
    callbackMap.set(eventName, [...cbList, callback])
}
const $off = (eventName:string) => {
    callbackMap.delete(eventName)
}
// const { proxy } = getCurrentInstance() as ComponentInternalInstance

// const state = reactive({

// })
export default {
    $emits,
    $on,
    $off,
}
